'use strict';
module.exports = app => {
  const { BIGINT, TINYINT, TEXT, INTEGER } = app.Sequelize;

  const NewsComment = app.model.define('news_comment', {

    article_id: {
      type: INTEGER,
      allowNull: false,
      comment: '文章id',
    },
    user_id: {
      type: INTEGER,
      allowNull: false,
      comment: '评论者id',
    },
    reply_user_id: {
      type: INTEGER,
      comment: '被回复的用户id',
    },
    parentId: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '父id，父id为0说明评论文章，否则为回复评论',
    },
    content: {
      type: TEXT,
      allowNull: false,
      comment: '评论内容',
    },
    is_top: {
      type: TINYINT,
      allowNull: false,
      defaultValue: 0,
      comment: '用于判断是否置顶，置顶为1，否则为0',
    },
    comment_count: {
      type: BIGINT,
      allowNull: false,
      defaultValue: 0,
      comment: '评论数',
    },
    like_count: {
      type: BIGINT,
      allowNull: false,
      defaultValue: 0,
      comment: '点赞数',
    },
    // is_liking:{
    //   type: BOOLEAN, // 布尔
    //   defaultValue: 0,
    //   comment: '当前用户是否点赞1 true ｜ 0 false',
    // },
    status: {
      type: TINYINT,
      allowNull: false,
      defaultValue: 1,
      comment: '状态(;1:审核中;2:审核通过;3审核失败;)',
    },

  });

  NewsComment.associate = () => {
    // 一篇文章包含一个分类 // 创建一个 一对多 关系, hasMany he belongsTo 关联一起使用;
    // app.model.Article.belongsTo(app.model.ArticleCategory, { as: 'category', foreignKey: 'category_id' });
    // // 这篇文章是哪个用户发的
    app.model.NewsComment.belongsTo(app.model.Article, { as: 'comment_article', foreignKey: 'article_id' });
    app.model.NewsComment.belongsTo(app.model.User, { as: 'comment_user', foreignKey: 'user_id' });
    app.model.NewsComment.belongsTo(app.model.User, { as: 'reply_user', foreignKey: 'reply_user_id' });
  };

  return NewsComment;
};
